Skip to content

fix(studio): a timeline clip click asks the source about its layer once - #8752

Merged
miguel-heygen merged 3 commits into
mainfrom
fix/studio-timeline-click-probes-once
Nov 24, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
fix/studio-timeline-click-probes-once

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Clicking a clip in the timeline now builds its canvas selection once and asks the source file about that layer once. Before, it did both twice.

Why

A clip click starts building the canvas selection (handleTimelineElementSelect). It also changes the timeline selection, which makes useTimelineSelectionPreviewSync build the same clip's selection again: it compares against the canvas selection, which isn't set yet while the first build runs. Both builds end in existsInSourceFile, so the source probe ran twice for one click.

In a same-origin preview both probes fall in the same tick, so probeSourceElement sends one request carrying the same target twice. In a sealed preview each build first waits on the frame's answer, so the two probes go as two separate POST .../file-mutations/probe-elements requests, along with two lookups over the frame's port. On published 0.9.91 (hyperframes preview), selecting a clip by the timeline gave 2 probe requests per selection sealed and 1 unsealed, in every run.

Async stacks for the two probes (v0.9.91, Studio dev server, a click on a clip, both modes):

  • onClick (TimelineLaneClip) → handleTimelineElementSelect → buildDomSelectionForTimelineElement → existsInSourceFile
  • useTimelineSelectionPreviewSync effect → syncSelection → resolveSelectionsForIds → buildDomSelectionForTimelineElement → existsInSourceFile

Related work

Refs #7846 (Studio's preview sealed by default): a sealed preview made more requests than a regular one for the same click.

How

hooks/useDomSelection.ts:

  • buildDomSelectionForTimelineElement now hands a clip's build that is still running to anyone who asks for the same clip in the same frame meanwhile (sharingRunningBuilds). Once the build settles, the next ask builds afresh.
  • A different frame (a reload or swap) never reuses a build. The shared map is made again whenever the builder's inputs change (composition path, comp map, master view).
  • The build itself moved out of the hook unchanged (buildTimelineSelection), so the hook's complexity stays where it was.

Test plan

  • fails without the fix: asks the source once when a clip click and the timeline's sync select the same clip in src/components/editor/previewPointerTargets.test.ts, for both a sealed and a same-origin frame. It failed on main with expected [...] to have a length of 1 but got 2: two probed targets for one selection.
  • On the devbox: that file 3 runs, green. Also 3 runs each: useDomSelection.test.ts, useDomSelectionSelectionGuards.test.ts, useTimelineSelectionPreviewSync.test.tsx, EditorShell.selectionSync.test.tsx, previewSelection.test.ts, LayersPanel.opaque.test.ts, useDomEditSession.test.tsx, green. The covering Studio test files the gate picked, green. tsc, Fallow and the pre-push hooks clean.
  • Real app: Studio's dev server at v0.9.91 with a console.trace on probeSourceElement, a click on a clip in the timeline, both modes (frame origin read in-run):
before after (this change applied)
regular (origin http://localhost:5431) 2 probes 1 probe
sealed (origin null) 2 probes 1 probe

No visible change

The selection a clip click makes is the same; only the requests behind it drop. Nothing is drawn differently, so there is no capture to compare.

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 51 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes at 209d846a630319e77beaa218f168fa94a2f362eb. The code is fine, but the PR turns the required file-size check red.

File size check fails with packages/studio/src/hooks/useDomSelection.ts has 628 lines (max 600). The file is 587 lines on main, and this PR adds buildTimelineSelection and sharingRunningBuilds (net +41). The fix is to move those two module-level helpers, and their two types, into a sibling module such as hooks/timelineSelectionBuild.ts and import them. They already take everything they need as arguments, so the move is mechanical.

Everything else from my review still holds:

  • Red-first. With main's useDomSelection.ts, both cases of "asks the source once when a clip click and the timeline's sync select the same clip" fail with expected [...] to have a length of 1 but got 2. At the head, 3 files and 50 tests pass.
  • Sharing. It shares only while a build is running, keyed by clip key and iframe. The entry is removed on settle, and a new iframe never shares an older build. Every caller uses the result as the clip's selection to commit through.

I'll approve once the split is pushed and CI is green.

Need: yes · Size: right in substance, but over the per-file line cap · Reuse: same build body · Simpler: n/a · Structure: move the helpers out to fit the cap
Risk: low

— Rames

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at d13f4d25d0006c4dcd250449ebc953fa6d054fc5. This resolves my change request.

buildTimelineSelection, sharingRunningBuilds and their two types moved into hooks/timelineSelectionBuild.ts. Across the two files, the only lines that differ between 209d846a and this head are two added export keywords and the moved imports. Every other line is identical. useDomSelection.ts is now 566 lines, under the 600 cap.

My earlier review stands:

  • Red-first. With main's code, both "asks the source once…" cases fail with length of 1 but got 2.
  • Sharing. A build is shared only while it is running, keyed by clip and iframe, and the entry is removed when it settles.

This approval is gated on CI green at this head.

Need: yes · Size: right · Reuse: same build body · Simpler: none · Structure: good, the helpers sit beside the hook
Risk: low

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 7aec1af Nov 24, 2026
80 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-timeline-click-probes-once branch November 24, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants